<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="科室名称" prop="departmentName">
        <el-input
            v-model="queryParams.departmentName"
            placeholder="请输入科室名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="departmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="科室编号" align="center" prop="departmentId" />
      <el-table-column label="科室名称" align="center" prop="departmentName" />
      <el-table-column label="医生数量" align="center" prop="doctorCount" />
      <el-table-column label="问诊数量" align="center" prop="numberOfConsultations" />
<!--      <el-table-column label="评分" align="center" prop="grade" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button plain  @click="dialogTableVisible1(scope.row.departmentId)">查看</el-button>

          <el-dialog v-model="dialogTableVisible" title="" width="800">
            <el-table :data="gridData">
              <el-table-column property="rankOfPhysician"  label="医师等级" width="150" v-if="rankOfPhysician==1" >普通医生</el-table-column>
              <el-table-column property="rankOfPhysician" v-if="rankOfPhysician==2" label="医师等级" width="150" >专家医生</el-table-column>
              <el-table-column property="rankOfPhysician" v-if="rankOfPhysician==3" label="医师等级" width="150" >主任医师</el-table-column>
              <el-table-column property="numPhysicians" label="医生人数" width="200" />
              <el-table-column property="numberOfConsultations" label="问诊次数" />
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                  <el-button link type="primary"  @click="access(scope.row.rankOfPhysician)">进入</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-dialog>

        </template>

      </el-table-column>


    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />


  </div>
</template>

<script setup name="Department">
import {listManagement, ListPhysician} from "@/api/manage/AdministrativeOffice.js";
import {useRoute, useRouter} from "vue-router";
import { reactive, ref } from 'vue';


const { proxy } = getCurrentInstance();

const gridData = ref([]);
const departmentList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const dialogTableVisible = ref(false);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const route = useRoute();
const router = useRouter();

let hospitalId = route.query.hospitalId;
let rankOfPhysician = route.query.hospitalId;
let departmentId = route.query.hospitalId;
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    departmentName: null,
  },
  rules: {

  }
});

const { queryParams, form, rules } = toRefs(data);

function dialogTableVisible1(departmentId){
  dialogTableVisible.value = true
  console.log(departmentId)
  router.push({query:{departmentId:departmentId}});
}

function access(rankOfPhysician){
  router.push({path:'/manage/AttendingPhysician',query:{rankOfPhysician:rankOfPhysician}});
}


function getData() {
  loading.value = true;

  ListPhysician(departmentId).then(response => {
    gridData.value = response.data;
    console.log(response)
    total.value = response.data.total;
    loading.value = false;
  });
}

function check () {
  router.push('/doctor/rank');
}

/** 查询科室列表 */
function getList() {
  loading.value = true;


  listManagement(hospitalId).then(response => {
    departmentList.value = response.data;
    console.log(response)
    total.value = response.data.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    departmentId: null,
    departmentName: null,
    grade: null,
    score: null
  };
  proxy.resetForm("departmentRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.departmentId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

getData();
getList();
</script>
